#!/usr/bin/python
# -*-coding:utf-8-*-
###############################################################
## Name       : clk
## Author     : xiaotu
## Time       : 2022-05-20 10:01:16
## Description:
## 
## 
###############################################################

import sys
import os
import re
import argparse
import math

class CLK():
    def __init__(self, value, unit, flag):
        self.value = float(value)
        self.unit = unit
        self.flag = flag
    
    def __str__(self):
        ret = "Frequency:\n"
        ret += "    " + str(self.Hz_value) + "Hz\n"
        ret += "    " + str(self.KHz_value) + "KHz\n"
        ret += "    " + str(self.MHz_value) + "MHz\n"
        ret += "    " + str(self.GHz_value) + "GHz\n"
        ret += "    " + str(self.THz_value) + "THz\n"
        
        ret += "\n"
        
        ret += "Period:\n"
        ret += "    " + str(self.s_value) + "s\n"
        ret += "    " + str(self.ms_value) + "ms\n"
        ret += "    " + str(self.us_value) + "us\n"
        ret += "    " + str(self.ns_value) + "ns\n"
        ret += "    " + str(self.ps_value) + "ps\n"
        
        return ret
    
    def cal(self):
        if self.flag == 1: #Hz
            if self.unit == 1: #5Hz
                self.Hz_value    = float(self.value)
                self.KHz_value  = float(self.value / 1000)
                self.MHz_value  = float(self.value / 1000000)
                self.GHz_value  = float(self.value / 1000000000)
                self.THz_value  = float(self.value / 1000000000000)
            elif self.unit == 3:
                self.Hz_value    = float(self.value * 1000)
                self.KHz_value  = float(self.value)
                self.MHz_value  = float(self.value / 1000)
                self.GHz_value  = float(self.value / 1000000)
                self.THz_value  = float(self.value / 1000000000)
            elif self.unit == 6:
                self.Hz_value    = float(self.value * 1000000)
                self.KHz_value  = float(self.value * 1000)
                self.MHz_value  = float(self.value)
                self.GHz_value  = float(self.value / 1000)
                self.THz_value  = float(self.value / 1000000)
            elif self.unit == 9:
                self.Hz_value    = float(self.value * 1000000000)
                self.KHz_value  = float(self.value * 1000000)
                self.MHz_value  = float(self.value * 1000)
                self.GHz_value  = float(self.value)
                self.THz_value  = float(self.value / 1000)
            else:
                self.Hz_value    = float(self.value * 1000000000000)
                self.KHz_value  = float(self.value * 1000000000)
                self.MHz_value  = float(self.value * 1000000)
                self.GHz_value  = float(self.value * 1000)
                self.THz_value  = float(self.value)
            self.s_value     = float(1 / self.Hz_value)
            self.ms_value   = float(1 / self.KHz_value)
            self.us_value    = float(1 / self.MHz_value)
            self.ns_value    = float(1 / self.GHz_value)
            self.ps_value    = float(1 / self.THz_value)
        else: #s
            if self.unit == 1: #5s
                self.s_value   = float(self.value)
                self.ms_value = float(self.value * 1000)
                self.us_value  = float(self.value * 1000000)
                self.ns_value  = float(self.value * 1000000000)
                self.ps_value  = float(self.value * 1000000000000)
            elif self.unit == 3: #5ms
                self.s_value   = float(self.value / 1000)
                self.ms_value = float(self.value )
                self.us_value  = float(self.value * 1000)
                self.ns_value  = float(self.value * 1000000)
                self.ps_value  = float(self.value * 1000000000)
            elif self.unit == 6: #5us
                self.s_value   = float(self.value / 1000000)
                self.ms_value = float(self.value / 1000)
                self.us_value  = float(self.value )
                self.ns_value  = float(self.value * 1000)
                self.ps_value  = float(self.value * 1000000)
            elif self.unit == 9: #5ns
                self.s_value   = float(self.value / 1000000000)
                self.ms_value = float(self.value / 1000000)
                self.us_value  = float(self.value / 1000)
                self.ns_value  = float(self.value)
                self.ps_value  = float(self.value * 1000)
            elif self.unit == 12: #5ps
                self.s_value   = float(self.value / 1000000000000)
                self.ms_value = float(self.value / 1000000000)
                self.us_value  = float(self.value / 1000000)
                self.ns_value  = float(self.value / 1000)
                self.ps_value  = float(self.value)
            self.Hz_value    = float(1 / self.s_value)
            self.KHz_value  = float(1 / self.ms_value)
            self.MHz_value  = float(1 / self.us_value)
            self.GHz_value  = float(1 / self.ns_value)
            self.THz_value  = float(1 / self.ps_value)
                
def input_proc():
    input = sys.argv[1]
    res = re.match(r"([\d\.]+)\s*(\w+)", input)
    if res:
        value = res.group(1)
        tmp   = res.group(2)
        unit = 9
        flag = 1
        if tmp.find("M") >= 0:
            unit = 6
            flag = 1 #频率，如900MHz
        elif tmp.find("G") >= 0:
            unit = 9
            flag = 1
        elif tmp.find("T") >= 0:
            unit = 12
            flag = 1
        elif tmp.find("K") >= 0:
            unit = 3
            flag = 1
        elif tmp.find("Hz") >= 0:
            unit = 1
            flag = 1
        elif tmp.find("n") >= 0:
            unit = 9
            flag = 0 #周期，如5ns
        elif tmp.find("m") >= 0:
            unit = 3
            flag = 0
        elif tmp.find("u") >= 0:
            unit = 6
            flag = 0
        elif tmp.find("p") >= 0:
            unit = 12
            flag = 0            
        elif tmp.find("s") >= 0:
            unit = 1
            flag = 0
        else:
            sys.exit(0)

        return CLK(value, unit, flag)
pass


def main():
    clk = input_proc()
    clk.cal()
    print(clk)

if __name__ == '__main__':
    main()
